home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 113_01 / a68symb.c < prev    next >
Text File  |  1985-03-09  |  5KB  |  182 lines

  1. /*
  2.     HEADER:        CUG113;
  3.     TITLE:        6800 Cross-Assembler (BDS C Version);
  4.     FILENAME:    A68SYMB.C;
  5.     VERSION:    2.6;
  6.     DATE:        07/22/1985;
  7.  
  8.     DESCRIPTION:    "This program lets you use your CP/M-80-based computer
  9.             to assemble code for the Motorola 6800, 6801, 6802,
  10.             6803, 6808, and 68701 microprocessors.  The program is
  11.             written in BDS C for the best possible performance on
  12.             8-bit machines.  All assembler features are supported
  13.             except relocation, linkage, listing control, and
  14.             macros.";
  15.  
  16.     KEYWORDS:    Software Development, Assemblers, Cross-Assemblers,
  17.             Motorola, MC6800, MC6801;
  18.  
  19.     SEE-ALSO:    CUG149, 6801 Cross-Assembler (Portable);
  20.  
  21.     SYSTEM:        CP/M-80;
  22.     COMPILERS:    BDS C;
  23.  
  24.     WARNINGS:    "This package is specifically tailored to CP/M-80
  25.             machines and the rather non-standard, but high-
  26.             performance BDS C compiler.  For other environments,
  27.             use the portable version of this package on CUG149.";
  28.  
  29.     AUTHORS:    William C. Colley III;
  30. */
  31.  
  32. /*
  33.     6800/6801 Cross-Assembler  v 2.6
  34.  
  35.     May, 1980
  36.  
  37.     July, 1980 -- Rev. 2.2 consisting of fixing the M errors that
  38.         come from forward references in FDB and FCB pseudo-ops.
  39.  
  40.     October, 1980 -- Rev. 2.3 consisting of updating the assembly
  41.         language file and I/O routines to match and take
  42.         advantage of BDS C V1.4.
  43.  
  44.     October, 1983 -- Rev. 2.4 consisting of adding the CPU pseudo-op,
  45.         adding the 6801 CPU's extra opcodes, and speeding up the
  46.         code a bit.
  47.  
  48.     September, 1984 -- Rev. 2.5 consisting of fixing bugs with the symbol
  49.         table sort, the writing of files to specified drives, and the
  50.         handling of blank input lines.
  51.  
  52.     June, 1985 -- Rev. 2.6 consisting of fixing a bug in the IF block
  53.         nesting mechanism.
  54.  
  55.     Copyright (c) 1980,83,84,85 William C. Colley, III.
  56.  
  57. File:    a68symb.c
  58.  
  59. Routines to manipulate the symbol table.
  60. */
  61.  
  62. /*  Get Globals:  */
  63.  
  64. #include "a68.h"
  65.  
  66. /*
  67. This function adds a new entry to the symbol table.  The function
  68. returns values of either 0 or -1.  If the value is 0, the symbol is
  69. already in the table and the global variable sympoint points to the
  70. existing entry.  If the value is -1, the symbol has just been entered
  71. into the table and sympoint points to the new entry.  If the symbol
  72. table is full, the function triggers an abort of the assembly.
  73. */
  74.  
  75. addsym(symbol)
  76. char *symbol;
  77. {
  78.     int t;
  79.  
  80.     if ((t = slookup(symbol)) > 0) wipeout("\nSymbol Table Overflow.\n");
  81.     if (t) movmem(symbol, sympoint, SYMLEN);
  82.     return t;
  83. }
  84.  
  85. /*
  86. This function checks the symbol table for a given symbol.  The function returns
  87. one of three values as follows:
  88.  
  89.      1 = symbol not found and symbol table full.
  90.      0 = symbol found.  sympoint points to the matching entry.
  91.     -1 = symbol not found.  sympoint points to where the symbol
  92.          should have been.
  93.  
  94. The symbol table is accessed using a hashing function with linear rehashing.
  95. */
  96.  
  97. slookup(symbol)
  98. char *symbol;
  99. {
  100.     int temp;
  101.  
  102.     temp = sympoint = &symtbl[hash(symbol)];
  103.     while(sympoint -> symname[0] & 0x7f) {
  104.     if (symcmp(symbol,sympoint->symname) == 0) return 0;
  105.     if (++sympoint == symend) sympoint = symtbl;
  106.     if (sympoint == temp) return 1;
  107.     }
  108.     return -1;
  109. }
  110.  
  111. /*
  112. This function returns a hash value for a given symbol.  The hash value
  113. is calculated by folding the symbol name up into 16 bits (2 bytes, thus
  114. the symbol length must be even) mod the number of symbols.
  115. */
  116.  
  117. hash(symbol)
  118. char *symbol;
  119. {
  120.     char i;
  121.     unsigned j;
  122.  
  123.     for (i = j = 0; i < (SYMLEN / 2); ++i)
  124.     j += (*symbol++ << 8) + *symbol++;
  125.  
  126.     return j % SYMBOLS;
  127. }
  128.  
  129. /*
  130. Function to sort the symbol table.  The function
  131. returns the number of entries in the table.
  132. */
  133.  
  134. sortsym()
  135. {
  136.     int n, symcmp();
  137.     struct symbtbl *tptr;
  138.  
  139.     n = 0;
  140.     for (tptr = sympoint = symtbl; tptr < symend; ++tptr) {
  141.     if (tptr -> symname[0] & 0x7f) {
  142.         movmem(tptr->symname,(sympoint++)->symname,(SYMLEN+2));  ++n;
  143.     }
  144.     }
  145.     qsort(&symtbl,n,(SYMLEN+2),&symcmp);  return n;
  146. }
  147.  
  148. /*
  149. This function compares two symbols.  It returns zero if the
  150. symbols are the same, not zero if they are different.
  151. */
  152.  
  153. symcmp(sym1,sym2)
  154. char *sym1, *sym2;
  155. {
  156.     char i;
  157.     int t;
  158.  
  159.     for (i = SYMLEN; i; --i) {
  160.     if (t = (*sym1++ & 0x7f) - (*sym2++ & 0x7f)) break;
  161.     }
  162.     return t;
  163. }
  164.  
  165. /*
  166. Function to abort an assembly.  The parameter reason holds a string that
  167. will be printed to explain why the assembly bombed.
  168. */
  169.  
  170. wipeout(reason)
  171. char *reason;
  172. {
  173.     puts(reason);  exit();
  174. }
  175.  0; i < (SYMLEN / 2); ++i)
  176.     j += (*symbol++ << 8) + *symbol++;
  177.  
  178.     return j % SYMBOLS;
  179. }
  180.  
  181. /*
  182. Fun